package com.activeMQ.config;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Topic;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.config.SimpleJmsListenerContainerFactory;

/**
 * @Description ActiveMQ 配置类
 *
 * @author 堆堆堆
 * @date 2018年4月17日 下午12:13:20
 */
@Configuration
public class ActiveMQConfig {

	/**
	 * @Description 注入 queue1
	 *
	 * @return
	 */
	@Bean(name = "queue1")
	public Queue queue1() {
		return new ActiveMQQueue("queue1");
	}

	/**
	 * @Description 注入 queue2
	 *
	 * @return
	 */
	@Bean(name = "queue2")
	public Queue queue2() {
		return new ActiveMQQueue("queue2");
	}

	/**
	 * @Description 注入 topic1
	 *
	 * @return
	 */
	@Bean(name = "topic1")
	public Topic topic1() {
		return new ActiveMQTopic("topic1");
	}

	/**
	 * @Description 注入 topic2
	 *
	 * @return
	 */
	@Bean(name = "topic2")
	public Topic topic2() {
		return new ActiveMQTopic("topic2");
	}

	/**
	 * @Description 开启 pub / sub 消息模型，默认关闭
	 *
	 * @param connectionFactory
	 * @return
	 */
	@Bean
	JmsListenerContainerFactory<?> jmsContainerFactory(ConnectionFactory connectionFactory) {
		SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
		factory.setConnectionFactory(connectionFactory);
		factory.setPubSubDomain(true);
		return factory;
	}
}
